package com.example.springboot.mapper;

import com.example.springboot.entity.User;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author shkstart
 * @create 2024-03-14-15:26

//@Mapper
public interface UserMapper1 {

    @Insert("insert into `user` (username,password,name,phone,email,address,avatar,role) values (#{username}," +
            "#{password},#{name},#{phone},#{email},#{address},#{avatar},#{role})")
    void insert(User user);

    //asc正序查询默认 desc 倒序查询
    @Select("select * from `user`")
    List<User> findAll();

    @Update("update `user` set username=#{username},password=#{password},name=#{name},phone=#{phone}," +
            "email=#{email},address=#{address},avatar=#{avatar},role=#{role} where id=#{id}")
    void updateUser(User user);


    @Select("select * from `user` where id=#{id}")
    User findUserById(Integer id);


    @Delete("delete from `user` where id=#{id}")
    void deleteById(Integer id);

    @Delete("delete from `user` where id = #{id}")
    void batchDeleteUser(Integer id);

    //Parameter 'username' not found. Available parameters are [arg1, arg0, param1, param2] 加上@Param 无法识别参数
    @Select("select * from `user` where username=#{username} and name=#{name}")
    List<User> findUserByMo(@Param("username") String username,@Param("name") String name);

    //多字段模糊查询
    @Select("select * from `user` where username like concat('%',#{username},'%') and name like" +
            " concat('%',#{name},'%') order by id desc")
    List<User> selectByMo(@Param("username") String username,@Param("name") String name);


    @Select("select * from `user` where username like concat('%',#{username},'%') and name like " +
            "concat('%',#{name},'%') order by id desc limit #{skpNum},#{pageSize}")
    List<User> getPage(@Param("skpNum")Integer skpNum,@Param("pageSize")Integer pageSize,@Param("username")String username,@Param("name") String name);

    @Select("select count(id) from `user` where username like concat('%',#{username},'%') and name like " +
            "concat('%',#{name},'%') order by id desc")
    Integer getCountPage(@Param("username")String username,@Param("name") String name);

    @Select("select * from `user` where username=#{username} ")
    User selectByUsername(String username);
}
 */